package com.example.serviceheadlines.controller;

import com.example.serviceheadlines.service.IHeadlinesCommentService;
import com.tangyuan.aspect.AutoLog;
import com.tangyuan.common.result.Result;
import com.tangyuan.dto.HeadlinesCommentDto;
import com.tangyuan.model.HeadlinesComment;
import com.tangyuan.model.User;
import com.tangyuan.common.util.CommStatus;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Description: headlines_comment
 * @Author: jeecg-boot
 * @Date: 2024-03-18
 * @Version: V1.0
 */
@Api(tags = "headlines_comment")
@RestController
@RequestMapping("/headlines")
@Slf4j
public class HeadlinesCommentController {
    @Autowired
    private IHeadlinesCommentService headlinesCommentService;


    /**
     * 百家评论及回复评论
     *
     * @return
     */
    @AutoLog(value = "百家评论及回复评论")
    @PostMapping("/addComment")
    public Result addVideoThumpById(@RequestHeader(name = "Authorization", required = false) String token,
                                    @RequestBody @Valid HeadlinesCommentDto headlinesCommentDto) {
        User user = CommStatus.getUser(token);
        return headlinesCommentService.addComment(user, headlinesCommentDto);
    }

    //查询评论(根据视频id查 分页)
    @AutoLog(value = "查询评论(根据视频id查分页)")
    @GetMapping("/comment/query")
    public Result<Object> selectCommentByVideoId(
            @RequestHeader(name = "Authorization", required = false) String token,
            HeadlinesComment headlinesComment,
            @RequestParam(value = "pageSize") Integer pageSize,
            @RequestParam(value = "pageNum") Integer pageNum) {
        User user = CommStatus.getUser(token);
        return headlinesCommentService.selectCommentByHeadlinesId(user, headlinesComment, pageSize, pageNum);
    }
}
